//
//  HandleHistoryCellTableViewCell.m
//  Utils
//
//  Created by enghou on 2018/4/19.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "HandleHistoryCellTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "NetWorkerManager.h"
@interface HandleHistoryCellTableViewCell()
@property (weak, nonatomic) IBOutlet UIImageView *stateImageView;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIImageView *firstImageView;

@property (weak, nonatomic) IBOutlet UIImageView *secondImageView;

@property (weak, nonatomic) IBOutlet UIImageView *thirdImageView;

@property (weak, nonatomic) IBOutlet UIView *downLine;

@property (weak, nonatomic) IBOutlet UIView *upperLine;

@end


@implementation HandleHistoryCellTableViewCell

- (IBAction)tapFirst:(id)sender {
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ShowWithObject" object:self.model.files[0]];
}
- (IBAction)tapSecond:(id)sender {
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ShowWithObject" object:self.model.files[1]];
}
- (IBAction)tapThird:(id)sender {
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ShowWithObject" object:self.model.files[2]];
}


-(void)setModel:(HandleHistoryItemModel *)model{
    _model = model;
    if (_model.current) {
        [self.stateImageView setImage:[UIImage imageNamed:@"icon_process_selected"]];
    }else{
        [self.stateImageView setImage:[UIImage imageNamed:@"icon_process_normal"]];
    }
    if (_model.hasPrevious) {
        _downLine.hidden = NO;
    }else{
        _downLine.hidden = YES;
    }
    if (_model.hasNext) {
        _upperLine.hidden = NO;
    }else{
        _upperLine.hidden = YES;
    }
    self.dateLabel.text = _model.time;
    self.descLabel.text = _model.event_desc;
    self.contentLabel.text = _model.event_content;
    NSArray *files = _model.files;
    if ([files count] == 0) {
        _firstImageView.hidden = YES;
        _secondImageView.hidden = YES;
        _thirdImageView.hidden = YES;
        return;
    }
    if ([files count] == 1) {
        _firstImageView.hidden = NO;
        _secondImageView.hidden = YES;
        _thirdImageView.hidden = YES;
        FileItemModel *file = files[0];
        if (file.type == Document) {
            _firstImageView.image = [UIImage imageNamed:@"icon_file"];
        }else if (file.type == Image){
            [_firstImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ServerPath,file.path]]];
        }else if (file.type == Video){
            [_firstImageView setImage:[UIImage imageNamed:@"icon_video"]];
        }else if (file.type == Audio){
            [_firstImageView setImage:[UIImage imageNamed:@"icon_audio"]];
        }
        return;
    }
    
    if ([files count] == 2) {
        _firstImageView.hidden = NO;
        _secondImageView.hidden = NO;
        _thirdImageView.hidden = YES;
        FileItemModel *file = files[0];
        if (file.type == Document) {
            _firstImageView.image = [UIImage imageNamed:@"icon_file"];
        }else if (file.type == Image){
            [_firstImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ServerPath,file.path]]];
        }else if (file.type == Video){
            [_firstImageView setImage:[UIImage imageNamed:@"icon_video"]];
        }else if (file.type == Audio){
            [_firstImageView setImage:[UIImage imageNamed:@"icon_audio"]];
        }
        
        FileItemModel *file1 = files[1];
        if (file1.type == Document) {
            _secondImageView.image = [UIImage imageNamed:@"icon_file"];
        }else if (file1.type == Image){
            [_secondImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ServerPath,file1.path]]];
        }else if (file1.type == Video){
            [_secondImageView setImage:[UIImage imageNamed:@"icon_video"]];
        }else if (file1.type == Audio){
            [_secondImageView setImage:[UIImage imageNamed:@"icon_audio"]];
        }
        return;
    }
    
    if ([files count] == 2) {
        _firstImageView.hidden = NO;
        _secondImageView.hidden = NO;
        _thirdImageView.hidden = NO;
        FileItemModel *file = files[0];
        if (file.type == Document) {
            _firstImageView.image = [UIImage imageNamed:@"icon_file"];
        }else if (file.type == Image){
            [_firstImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ServerPath,file.path]]];
        }else if (file.type == Video){
            [_firstImageView setImage:[UIImage imageNamed:@"icon_video"]];
        }else if (file.type == Audio){
            [_firstImageView setImage:[UIImage imageNamed:@"icon_audio"]];
        }
        
        FileItemModel *file1 = files[1];
        if (file1.type == Document) {
            _secondImageView.image = [UIImage imageNamed:@"icon_file"];
        }else if (file1.type == Image){
            [_secondImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ServerPath,file1.path]]];
        }else if (file1.type == Video){
            [_secondImageView setImage:[UIImage imageNamed:@"icon_video"]];
        }else if (file1.type == Audio){
            [_secondImageView setImage:[UIImage imageNamed:@"icon_audio"]];
        }
        
        FileItemModel *file2 = files[2];
        if (file2.type == Document) {
            _secondImageView.image = [UIImage imageNamed:@"icon_file"];
        }else if (file2.type == Image){
            [_secondImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ServerPath,file2.path]]];
        }else if (file2.type == Video){
            [_secondImageView setImage:[UIImage imageNamed:@"icon_video"]];
        }else if (file2.type == Audio){
            [_secondImageView setImage:[UIImage imageNamed:@"icon_audio"]];
        }
        return;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapFirst:)];
    [self.firstImageView addGestureRecognizer:tap];
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapSecond:)];
    [self.secondImageView addGestureRecognizer:tap1];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapThird:)];
    [self.thirdImageView addGestureRecognizer:tap2];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
